{* $Id$ *}
{include_core file="admin/lib/header.html" title="用户展示"}
  <div class="page-header border-bottom clearfix">
    <h2 class="left">用户管理<span>在这里对用户进行管理</span></h2>
    <a href="{AnUrl('user/admin/add')}" class="btn btn-success btn-sm right"><i class="icon-add"></i>添加用户</a>
  </div>
  <div class="search-level1 clearfix" {if $is_advenced == 1}style="display:none;"{/if}>
    <form action="user/admin/manage_user" method="get">
      <input type="text" class="left" name="mobile" value="{$mobile}">
      <button type="submit" class="btn btn-success btn-sm left">搜索</button>
    </form>
  </div>

  
  <!--start:列表-->
  <table class="list-table">
    <thead><tr>
      {if $status == 1}
      <th style="width:20px;"><input type="checkbox" class="selectAll"></th>
      {/if}
      <th style="width:60px;">编号</th>
      <th style="width:60px;">用户名</th>
      <th style="width:60px;">角色</th>
      <!-- <th style="width:60px;">头像</th> -->
      <th style="min-width:300px;">其他信息</th>
      <th style="width:130px;">注册时间</th>
      {if $status == 1}
      <th>积分/抱抱币</th>
      {/if}
      <th style="width:60px;">操作</th>
    </tr></thead>
    <tbody>
      {foreach $user_list as $k=>$v}
        <tr id="dataList{$v.id}" {if $k%2 == 1} class="bg-gray"{/if} data-id="{$v.id}">
          {if $status == 1}
          {if $v.id == 1}
            <td></td>
          {else}
            <td><input type="checkbox" class="listSelect"></td>
          {/if}
          {/if}
          <td class="js_userName">{$v.id}</td>
          <td class="js_userName">{$v.user_name}</td>
          <td>{$v.role_type}</td>
          <!-- <td>
              <img width="60" src="{user_helper::avatar($v['id'])}">
          </td> -->
          <td>
    {if $v.parent_id > 0}父级经销商:{$v.parent_user_name}<br/>{/if}
            {* 性别：{if $v.gender == 1}男{elseif $v.gender == 0}女{else}未知{/if}<br /> *}
            手机号码：{$v.mobile}<br />
            真实姓名：{$v.realname}<br>
            {if $v.role_id == user_config::AGENCY}
            签约门店：{$v.store_count}<br>
            旗下员工：{$v.pople_count}<br>
            订单数量: {$v.order_count}
            {elseif $v.role_id == user_config::MARKETING}
            签约门店：{$v.store_count}<br>
            {elseif $v.role_id == user_config::STORE_MANAGER || $v.role_id == user_config::STORE_OWNER}
            订单数量: {$v.order_count}<br>
            {/if}
          </td>
          <td>{time_format($v.add_time)}</td>
          <td>
              <a href="{AnUrl("user/admin/manage_user/delete?id={$v.mobile}")}" class="btn btn-danger btn-xs deleteOneUser"><i class="icon-trash icon-white"></i>彻底删除(慎用)</a>
          </td>
        </tr>
      {foreachelse}
          <tr><td class="txtleft" colspan="6">暂无数据</td></tr>
      {/foreach}
    </tbody>
    {if $status == 1}
    <tfoot><tr><td><input type="checkbox" class="selectAll"></td><td colspan="6"><a href="{AnUrl("user/admin/manage_user/delete")}" class="btn btn-danger btn-xs deleteAll">批量禁用</a></td></tr></tfoot>
    {/if}
  </table>
  <script type="text/javascript">
  
  $(function(){
      
      
      if ('{user_config::AGENCY}' == $('select[name="search_filter[role_id]"]').val()) {
          $('.js_assistant').show();
      } else {
          $('.js_assistant').hide();
          $('select[name="assistant_user_id"]').val('0');
      }
      
      $('select[name="search_filter[role_id]"]').change(function(){
          if ('{user_config::AGENCY}' == $(this).val()) {
              $('.js_assistant').show();
          } else {
              $('.js_assistant').hide();
              $('select[name="assistant_user_id"]').val('0');
          }
      });
      
      
   // 将制定的元素设置为可是区域居中
      function center_format(obj){
          // 获取可是窗口的宽度
          var winWidth  = $(window).width();
          var winHeight = $(window).height();
          
          // 计算窗体本身的宽和高
          var objWidth = obj.width();
          var objHeight = obj.height();
          
          // 设置窗体的位置
          obj.css('position', 'fixed');
          // 计算left和top值
          var objLeft = (winWidth - objWidth)/2;
          var objTop = (winHeight - objHeight)/3; // 如果除以2感觉不垂直居中
          obj.css('left', objLeft+'px');
          obj.css('top', objTop+'px');
          
      }
      
    // 高级搜索
    $('.js_advanced').click(function(e){
      e.preventDefault();
      var thisObj = $(this);
      var outBox  = thisObj.closest('form');
      if (thisObj.hasClass('js_isOpen')) {
        thisObj.removeClass('js_isOpen open');
        outBox.find('input').show();
        outBox.find('button').show();
        $('.js_advancedForm').hide();
      } else {
        thisObj.addClass('js_isOpen open');
        outBox.find('input').hide();
        outBox.find('button').hide();
        $('.js_advancedForm').show();
      }
    });
    
    // 查看子经销商
    $('.js_showSecondDealer').click(function(){
        // 获取此一级经销商的id
        var $url = $(this).attr('url');
        var th = $(this);
        // 发送ajax查询子经销商
        $.ajax({
            url : $url,
            type : "get",
            dataType : 'json',
            error : function () {
              showMsg('此经销商没有二级经销商!');
            },
            success : function(res){
                if (res != 'no') {
                    var infoList = res;
                    $('.float-bg').show();
                    var list = $('.js_secondDealerList').clone(true, true);
                   	list.find('.js_dealerTitle').html(th.parents('tr').find('td.js_userName').html()+'的子经销商信息');
                    $('body').append(list);

                    // 设置弹窗的位置
                    center_format(list);
                    list.show();
                    
                    // 说明 存在二级经销商
					for (var i in infoList) {
					    var info = $('<tr><td style="width:200px;text-align:center;border:1px solid #ccc">'+infoList[i]["user_name"]+'</td><td style="width:200px;text-align:center;border:1px solid #ccc">'+infoList[i]["mobile"]+'</td></tr>');
					    list.find('.js_expressTable').append(info);
					}
                    
                    list.find('.js_closeDealerList').click(function(){
                        list.hide();
                        list.remove();
                        $('.float-bg').hide();
                    });
                    
                } else {
                    alert('此经销商没有二级经销商!');
                }
            }
        });
        
        return false;
    });
    
  });
  

  
  </script>
<div class="float-confirm js_secondDealerList" style="z-index: 20000;display: none; width:auto; height:auto; margin:0px; position : fixed;">
  <div class="float-confirm-con" style="margin:0px 0px;">
  	<a class="icon-close js_closeDealerList" href="javascript:void(0);">关闭</a>
    <p style="font-size:18px;color:#23a18b;" class="js_dealerTitle">子经销商信息</p>
    <div style="width:auto;height:1px;background:#CCC;margin-bottom:20px;"></div>
    <div style="width:500px;max-height:400px;over-flow:hidden;margin-bottom:15px;">
      <table style="line-height:50px;border:1px solid #ccc;margin:0 auto;" class="js_expressTable">
        <tr>
          <th style="width:200px;text-align:center;border:1px solid #ccc">用户名</th>
          <th style="width:200px;text-align:center;border:1px solid #ccc">手机号码</th>
        </tr>
        
      </table>
      <table style="line-height:50px;display:none;width:400px;line-height:24px;" class="js_refundTable">
      </table>
    </div>
    <div style="width:auto;height:1px;background:#CCC;margin-bottom:20px;"></div>
  </div>
</div>
<div class="float-bg" style="z-index: 19999; display: none"></div>
  {include_core file="admin/lib/pager.html"}
<!--end:列表-->
{load_js file='zclip/jquery.zclip.min.js'}
{load_js file='zclip/ZeroClipboard.js'}
{include_core file="admin/lib/footer.html"}